﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BattleThis.Core
{
	/// <summary>
	/// Service for the game map.
	/// </summary>
	public class MapService
	{

		#region Variablen
		private static IEnumerable<Map> MemoryDummy = CreateDummyMaps();
		#endregion

		#region Properties

		#endregion

		#region Methoden

		/// <summary>
		/// Creates the dummy maps.
		/// </summary>
		/// <returns></returns>
		protected static IEnumerable<Map> CreateDummyMaps()
		{
			var dummyMaps = new List<Map>();

			var sample1 = new Map( "Sample1", new MapSize(21,15), 2 );

			sample1.Fields[ 0, 0 ].LandScape = Landscape.Mounten;
			sample1.Fields[ 0, 1 ].LandScape = Landscape.Mounten;
			sample1.Fields[ 1, 1 ].LandScape = Landscape.Mounten;
			sample1.Fields[ 1, 0 ].LandScape = Landscape.Mounten;

			sample1.Fields[ 3, 1 ].LandScape = Landscape.Sea;
			sample1.Fields[ 3, 2 ].LandScape = Landscape.Sea;
			sample1.Fields[ 3, 3 ].LandScape = Landscape.Sea;

			var sample2 = new Map( "Sample2", new MapSize( 5,5 ), 2 );

			dummyMaps.Add( sample1 );
			dummyMaps.Add( sample2 );

			return dummyMaps;
			
		}

		/// <summary>
		/// Loads the map templates. Thats all possible maps you can play.
		/// </summary>
		/// <returns></returns>
		public IEnumerable<Map> LoadMaps()
		{
			return MemoryDummy;
		}

		/// <summary>
		/// Loads the map by the name.
		/// </summary>
		/// <param name="name">The name of the map.</param>
		/// <returns></returns>
		public Map LoadMap( string name )
		{
			return this.LoadMaps().Where(x=>x.Name.Equals(name)).Single();
		}

		#endregion

	}
}